<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script>
var pageLoad = true;
var fid = "" == "${param.efid}" ? "id_1" : "${param.efid}";
if (typeof(iPanel) != "undefined"){
    pageLoad = false;
}

//获取模板访问路径
function getTemplatePath() {
   return "${_templatePath}";
}

//选择器
function idE(id) {
    return "string" == typeof id ? document.getElementById(id) : id;
}

//页面加载完成后调用
function onPageLoad(initFocusId) {
	pageLoad = true;
	
	if("${param.efid}" == "" && initFocusId != ""){
		setPageFocus(initFocusId);
	}
	else{
		setPageFocus(fid);
	}
}

//页面卸载时调用
function onPageUnload() {
	if (typeof(iPanel) != "undefined"){
    }
}

//定位页面焦点
function setPageFocus(id) {
    try{
        idE(id).focus();
    }catch (exception){
        //exception
    }
}

//页面跳转，historyMark表示跳转地址是否记录历史，记录为1不记录0
function gotoPage(pageUrl, object, historyMark) {
	var leavefid = "";
	if(object!=null){
    	var leavefid = object.id;
	}
    var updateUrl = "";
    if(leavefid!="" && historyMark == 1){
        updateUrl = addUrlParameter(pageUrl,'lfid',leavefid);
    }else{
        updateUrl = pageUrl;
    }
    window.location.href = updateUrl;
}

function gotoLink(pageUrl, id) {
	var leavefid = id;
    var updateUrl = "";
    if(leavefid!=""){
        updateUrl = addUrlParameter(pageUrl,'lfid',leavefid);
    }else{
        updateUrl = pageUrl;
    }
    window.location.href = updateUrl;
}

//播放返回链接为当前访问的链接
var playFlag = false;
function gotoPlay(playUrl,object) {
	if(playFlag) return;
	playFlag = true;
	var leavefid = '';
	if(object) {
		leavefid = object.id
	}
	var backUrl = "";
	var aPlayUrl = addUrlParameter(playUrl,'plbkurl',backUrl);
	playFlag = false;
	window.location.href = aPlayUrl;
}

//给指定URL增加链接参数
function addUrlParameter(url, paraName, paraValue) {
    if (paraName == '') return url;
    var updateUrl;
    if (url.indexOf(paraName) == -1) {
        if (url.indexOf("?") == -1)
            updateUrl = url + '?' + paraName + '=' + paraValue;
        else
            updateUrl = url + '&' + paraName + '=' + paraValue;
    }else{
    	var reg = new RegExp(paraName + "=\\w*","g");
    	updateUrl = url.replace(reg,paraName + "=" +paraValue);
    }
    return updateUrl;
}

function urlencode (str) {  
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');  
}

//退出按键
function onExistEvent() {
	 if(typeof(customOnKeyExit) == "function") { 
		 customOnKeyExit(); 
	 } else {
         var homeUrl = "";
         if(homeUrl){
             window.location.href = homeUrl;
         }else{
             history.back();
         }
     }
}

//返回按键
function onBackEvent() {
	if(typeof(customOnKeyBack) == "function") { 
		customOnKeyBack(); 
		return 0; 
	} else {
        var backUrl = "${_returnUrl}";
        if(backUrl == "" || backUrl == "null"){
            //history.back();
            window.location.href = "${wechatConfig.indexUrl}";
        }else{
            window.location.href = backUrl;
        }
    }
}

//=======================================================================================

function setCookie(name,value,expireHour){//两个参数，一个是cookie的名子，一个是值,
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + expireHour*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
}

function getCookie(name){//取cookies函数        
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}

function epgURL(url){
	var ourl=url||window.location.href;
	var href="";//?前面部分
	var params={};//url参数对象
	var jing="";//#及后面部分
	var init=function(){
		var str=ourl;
		var index=str.indexOf("#");
		if(index>0){
			jing=str.substr(index);
			str=str.substring(0,index);
		}
		index=str.indexOf("?");
		if(index>0){
			href=str.substring(0,index);
			str=str.substr(index+1);
			var parts=str.split("&");
			for(var i=0;i<parts.length;i++){
				var kv=parts[i].split("=");
				params[kv[0]]=kv[1];
			}
		}else{
			href=ourl;
			params={};
		}
	};
	this.set=function(key,val){
		params[key]=encodeURIComponent(val);
	};
	this.remove=function(key){
		if(key in params) params[key]=undefined;
	};
	this.get=function(key){
		return params[key];
	};
	this.toString=function(key){
		var strurl=href;
        var objps=[];
        for(var k in params){
            if(params[k]){
                objps.push(k+"="+params[k]);
            }
        }
        if(objps.length>0){
            strurl+="?"+objps.join("&");
        }
        if(jing.length>0){
            strurl+=jing;
        }
        return strurl;
	};
	init();
}

</script>